<?php

include "conn.php"; //引入数据库连接的文件。

//检测用户名是否重名
if (isset($_POST['username'])) {
    $user = $_POST['username'];
    $result = $conn->query("select * from regidtryho where username='$user'");
    if ($result->fetch_assoc()) { //存在
        echo true; //1
    } else {
        echo false; //空
    }
}


//接收用户注册的信息
if (isset($_POST['submit'])) {
    $user = $_POST['username'];
    $pass = sha1($_POST['password']);
    $email = $_POST['email'];

    //执行插入的sql语句。
    $conn->query("insert regidtryho values(null,'$username','$password','$email'");
    //如果注册成功，跳到登录页面
    header('location:http://localhost/Yoho/src/html/2.%e7%99%bb%e5%bd%95.html');
}